package demo1107.demo02;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/11/7 15:58
 */
public class Test02 {
    public static void main(String[] args) {
        Singleton1 i1 = Singleton1.getInstance();
        Singleton1 i2 = Singleton1.getInstance();
        System.out.println(i1);
        System.out.println(i2);
    }
}
class Singleton1{
    private Singleton1(){}

    private static Singleton1 singleton1;

    public static Singleton1 getInstance() {
        synchronized (Singleton1.class) {
            if (singleton1 == null) {
                singleton1 = new Singleton1();
            }
            return singleton1;
        }
    }
}